<?php
if ($db = new SQLiteDatabase( 'InstantInput.db' )) 
{
	$result = $db->query("SELECT name FROM sqlite_master WHERE type='table' AND name='Users'");
	if ($result->numRows() == 0) 
	{
		$db->queryExec('CREATE TABLE Users (sunet_id text, type text, email text, PRIMARY KEY (sunet_id))');
	}
	
	$result = $db->query("SELECT name FROM sqlite_master WHERE type='table' AND name='Classes'");
	if ($result->numRows() == 0) 
	{
		$db->queryExec("CREATE TABLE Classes (class_id integer PRIMARY KEY ASC, course text, title text, teacher text, start_time text, end_time text, days text, location text)");
	
		$db->queryExec("Insert INTO Classes (class_id, course, title, start_time, end_time, days, location) VALUES (0, 'CS 147', 'Introduction to Human-Computer Interaction Design', '1:15 PM', '2:05 PM', 'T R', 'Hewlett 201' )"); 
		$db->queryExec("Insert INTO Classes (class_id, course, title, start_time, end_time, days, location) VALUES (1, 'CS 547', 'Human-Computer Interaction Seminar', '12:50 PM', '2:05 PM', 'F', 'Gates B1' )"); 
	}
		
	$result = $db->query("SELECT name FROM sqlite_master WHERE type='table' AND name='User_Classes'");
	if ($result->numRows() == 0) 
	{
		$db->queryExec('CREATE TABLE User_Classes (id integer PRIMARY KEY ASC, sunet_id text, class_id int)');
	}
	
	$result = $db->query("SELECT name FROM sqlite_master WHERE type='table' AND name='Metrics'");
	if ($result->numRows() == 0) 
	{
		$db->queryExec('CREATE TABLE Metrics (metric_id integer PRIMARY KEY ASC, sunet_id text, class_id int, metric_type text, value int, time text)');
	}
	
	$result = $db->query("SELECT name FROM sqlite_master WHERE type='table' AND name='Threads'");
	if ($result->numRows() == 0) 
	{
		$db->queryExec('CREATE TABLE Threads (thread_id integer PRIMARY KEY ASC, sunet_id text, class_id int, post_time text, likes int, message text)');
	}
	
	$result = $db->query("SELECT name FROM sqlite_master WHERE type='table' AND name='Messages'");
	if ($result->numRows() == 0) 
	{
		$db->queryExec('CREATE TABLE Messages (message_id integer PRIMARY KEY ASC, sunet_id text, class_id int, thread_id int, post_time text, likes int, message text)');
	}
	
	$result = $db->query("SELECT name FROM sqlite_master WHERE type='table' AND name='Liked_Messages'");
	if ($result->numRows() == 0) 
	{
		$db->queryExec('CREATE TABLE Liked_Messages (liked_id integer PRIMARY KEY ASC, message_id int, sunet_id text)');
	}
} 
else 
{
	die($err);
}
?>



Database Created